package aex.action;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import aex.domain.Puser;
import aex.service.DateDictionaryService;
import aex.service.PuserService;
import aex.util.CU;
import aex.util.Constant;
import aex.util.PageBean;

import com.opensymphony.xwork2.ModelDriven;
/**
 * 会员管理action
 * @author JiangYouYao
 *
 */
@Controller("PuserManagerAction")
@Scope("prototype")
public class PuserManagerAction extends BaseActon implements ModelDriven<Puser> {

	
	private static final long serialVersionUID = 1L;
	@Resource(name = PuserService.SERVICE_NAME)
	PuserService puserService;
	
	@Resource(name=DateDictionaryService.SERVICE_NAME)
	DateDictionaryService ddService;
	
	
	Puser puser=new Puser();
	@Override
	public Puser getModel() {
		return puser;
	}

	public PuserManagerAction() {
		CU.deBugPrintln("PuserAction 创建");
	}
	
	
	public String userList(){
		String keyWord=request.getParameter("keyWord");
		PageBean<Puser> pageBean = new PageBean<Puser>();
		PageBean.initPageBean(pageBean, request, "&keyWord="+keyWord);
		pageBean = puserService.serchPuser(keyWord,pageBean);
		request.setAttribute("keyWord", keyWord);
		request.setAttribute("pageBean", pageBean);
		return "userList";
	}
	
	public String frozenAccount(){
		int id=Integer.parseInt( request.getParameter("id"));
		String  reason=CU.encodingUTF(request.getParameter("reason"));
		puser=puserService.findById(id);
		puser.setPuState(Constant.ACCOUNTSTATE_FROZEN+":"+reason);
		puserService.update(puser);
		ajaxPrint("账号已经冻结成功！");
		return null;
		
	}
	
	
	public String unfrozenAccount(){
		int id=Integer.parseInt( request.getParameter("id"));
		puser=puserService.findById(id);
		puser.setPuState("1");
		puserService.update(puser);
		ajaxPrint("账号已经解冻成功！");
		return null;
	}
	
	
	
	
	public String showUser(){
		String id=request.getParameter("id");
		request.setAttribute("hy", puserService.findById(Integer.parseInt(id)));
		return "showUser";
	}
	
}
